import type { ProjectConfig } from '#/config';
import { computed } from 'vue';
import { ContentEnum, ThemeEnum } from '@/enums/appEnum';
import { AppStorage } from '@2/app/core/ioc';

type RootSetting = Omit<
  ProjectConfig,
  'locale' | 'headerSetting' | 'menuSetting' | 'multiTabsSetting'
>;

export function useRootSetting() {
  // TODO-BaiHoo-Update: 更新初始化项目配置
  // const appStore = useAppStore();
  const projectConfig = AppStorage.getProjectConfig() as ProjectConfig;

  const getPageLoading = computed(() => AppStorage.getPageLoading());

  const getOpenKeepAlive = computed(() => projectConfig.openKeepAlive);

  const getSettingButtonPosition = computed(() => projectConfig.settingButtonPosition);

  const getCanEmbedIFramePage = computed(() => projectConfig.canEmbedIFramePage);

  const getPermissionMode = computed(() => projectConfig.permissionMode);

  const getShowLogo = computed(() => projectConfig.showLogo);

  const getContentMode = computed(() => projectConfig.contentMode);

  const getUseOpenBackTop = computed(() => projectConfig.useOpenBackTop);

  const getShowSettingButton = computed(() => projectConfig.showSettingButton);

  const getUseErrorHandle = computed(() => projectConfig.useErrorHandle);

  const getShowFooter = computed(() => projectConfig.showFooter);

  const getShowBreadCrumb = computed(() => projectConfig.showBreadCrumb);

  const getThemeColor = computed(() => projectConfig.themeColor);

  const getShowBreadCrumbIcon = computed(() => projectConfig.showBreadCrumbIcon);

  const getFullContent = computed(() => projectConfig.fullContent);

  const getColorWeak = computed(() => projectConfig.colorWeak);

  const getGrayMode = computed(() => projectConfig.grayMode);

  const getLockTime = computed(() => projectConfig.lockTime);

  const getShowDarkModeToggle = computed(() => projectConfig.showDarkModeToggle);

  const getDarkMode = computed(() => AppStorage.getDarkMode());

  const getLayoutContentMode = computed(() =>
    projectConfig.contentMode === ContentEnum.FULL ? ContentEnum.FULL : ContentEnum.FIXED,
  );

  function setRootSetting(setting: Partial<RootSetting>) {
    AppStorage.setProjectConfig(setting);
  }

  function setDarkMode(mode: ThemeEnum) {
    AppStorage.setDarkMode(mode);
  }
  return {
    setRootSetting,

    getSettingButtonPosition,
    getFullContent,
    getColorWeak,
    getGrayMode,
    getLayoutContentMode,
    getPageLoading,
    getOpenKeepAlive,
    getCanEmbedIFramePage,
    getPermissionMode,
    getShowLogo,
    getUseErrorHandle,
    getShowBreadCrumb,
    getShowBreadCrumbIcon,
    getUseOpenBackTop,
    getShowSettingButton,
    getShowFooter,
    getContentMode,
    getLockTime,
    getThemeColor,
    getDarkMode,
    setDarkMode,
    getShowDarkModeToggle,
  };
}
